package itheima02;

import utils.JDBCUtil;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * @author xxx
 * @date 2021/1/3 4:08
 * @description
 */
public class Test {
    public static void main(String[] args) {
        Connection connection=null;
        Statement statement=null;
        ResultSet resultSet=null;

        try{
            connection= JDBCUtil.getConnection();
            statement=connection.createStatement();

            String sql ="SELECT * FROM scores ";
            resultSet=statement.executeQuery(sql);

            while (resultSet.next()){
                Object a=resultSet.getInt(1);
                Object b=resultSet.getInt(2);
                Object c=resultSet.getString(3);

                System.out.println("编号: "+a+", 姓名: "+b+", 成绩: "+c);
            }

            String sql1="delete from scores where sid='1'";

            int hh=statement.executeUpdate(sql1);

            if(hh>0){
                System.out.println("删除成功");
            } else {
                System.out.println("删除失败");
            }
            JDBCUtil.release(connection,statement,resultSet);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
